#include <stdio.h>
#include <signal.h>
#include <unistd.h>

static void handler1(int s);

static void handler2(int s);

static void alrm_handler(int s);

int main(void)
{
	int cnt = 0;

	signal(SIGALRM, alrm_handler);
	alarm(5);
	signal(SIGINT, handler1);

	while (1) {
		write(1, "*", 1);
		cnt++;

		if (cnt == 20)
			signal(SIGINT, handler2);

		sleep(1);
	}

	return 0;
}

static void handler1(int s)
{
	write(1, "!!!\n", 5);
}

static void handler2(int s)
{
	write(1, "???\n", 5);

	sleep(10);
}

static void alrm_handler(int s)
{
	alarm(5);
	printf("ALARM!!!\n");
}

